import java.util.Arrays;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
//        Solution s = new Solution();
//        System.out.println();
    }
}

//按照左端点排序
class Solution {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, Comparator.comparingInt((p) -> p[0]));
        int countArrow = 0;
        long leftXEnd = Long.MIN_VALUE;
        for (int[] point : points) {
            int xStart = point[0];
            int xEnd = point[1];
            if (leftXEnd >= xStart) {
                leftXEnd = Math.min(xEnd, leftXEnd);
                continue;
            }
            countArrow++;
            leftXEnd = xEnd;
        }
        return countArrow;
    }
}

//按照右端点排序（官方）
class Solution1 {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, Comparator.comparingInt((p) -> p[1]));
        int minXEnd = points[0][1];        //xend最小是2^-31 + 1
        int countArrows = 1;
        for (int[] point : points) {
            if (point[0] > minXEnd) {
                minXEnd = point[1];
                countArrows++;
            }
        }
        return countArrows;
    }
}
